﻿using Mengsk.ProxyDelivery.Domain;
using Mengsk.ProxyDelivery.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Mengsk.ProxyDelivery.App.UI.Accounting
{
    /// <summary>
    /// SellerTradeView.xaml 的交互逻辑
    /// </summary>
    public partial class SellerTradeDetailWindow : Window
    {
        public SellerPay Trade { private get; set; }

        public SellerTradeDetailWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                List<SellerTradeDetail> details = new List<SellerTradeDetail>();
                OrderService os = ServiceContainer.GetService<OrderService>();
                details.AddRange(os.GetAllByField("tradeId", this.Trade.Id, 0, 0).Datas.Select(obj => new SellerTradeDetail(obj, this.Trade.Id)));
                details.AddRange(os.GetAllByField("tradeId2", this.Trade.Id, 0, 0).Datas.Select(obj => new SellerTradeDetail(obj, this.Trade.Id)));
                this.dgvItems.ItemsSource = details;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
    }


    public class SellerTradeDetail
    {

        public long OrderId { get; set; }

        public String Type { get; set; }

        public double Money { get; set; }

        public SellerTradeDetail(Mengsk.ProxyDelivery.Domain.Order order, long
            tradeId)
        {
            this.OrderId = order.Id;
            this.Type = order.PayId == tradeId ? "付款" : "差价";
            this.Money = order.TotalMoney;
        }
    }
}
